home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC04Cust.Ctrl / BC.Stds.asm < prev    next >
Encoding:
Assembly Source File  |  1990-05-17  |  13.0 KB  |  378 lines  |  [TEXT/pdos]

  1.  
  2.                     EJECT
  3. *******************************************************************************
  4. *
  5. InitTools           start
  6. *
  7. * Description:      Load and initialize the tools needed. Errors are detected
  8. *                   and FatalError is called if any occur. If there aren't any
  9. *                   errors, the list of menu templates is read and the menu-
  10. *                   bar is created.
  11. *
  12. *
  13. * Inputs:           NONE
  14. *
  15. * Outputs:          NONE
  16. *
  17. * External Refs:
  18. *                   Import FatalError
  19. *
  20. * Entry Points:     NONE
  21. *
  22. *******************************************************************************
  23.                     using Globals
  24.  
  25. ;
  26. ;   Tool Direct page offsets here
  27. ;
  28. QDDPage             equ $0000
  29. EMDPage             equ QDDPage+$0300
  30. CtlDPage            equ EMDPage+$0100
  31. MenuDPage           equ CtlDPage+$0100
  32. LEDPage             equ MenuDPage+$0100
  33. ToolDPSize          equ LEDPage+$0100
  34.  
  35.                     phk                 ; Save program bank register and
  36.                     plb                 ; load it as the data bank register
  37.  
  38.                     tdc
  39.                     sta MyDP            ; Save direct register
  40.  
  41.                     _TLStartup          ; Start Tool Locator
  42.  
  43.                     pha                 ; Space for result
  44.                     _MMStartup          ; Start memory manager
  45.                     PullWord MyID       ; Save it for later use
  46.  
  47.                     _MTStartup          ; Start up Misc Tools
  48.  
  49.                     _IMStartup          ; Start integer math toolset
  50.  
  51.                     PushLong #ToolTable ; Pointer to Tool table
  52.                     _LoadTools          ; Load all RAM based tools
  53.                     bcc IT0005          ; Carry clear means no error
  54.                     brl FatalError      ; Tools can't be loaded. Fatal error!
  55.  
  56. IT0005              ANOP
  57.  
  58. ; Get memory for Tool Direct pages
  59.  
  60.                     pha                 ; Room for result
  61.                     pha
  62.                     PushLong #ToolDPSize ; Number of bytes needed
  63.                     PushWord MyID       ; ID of this application
  64.                     PushWord #attrLocked+attrFixed+attrPage+attrBank
  65.                     PushLong #0         ; Allocate them in bank 0
  66.                     _NewHandle
  67.                     bcc IT0010          ; Test carry for error
  68.                     brl FatalError      ; If no memory we got a fatal error!
  69.  
  70. IT0010              PullLong DPHandle   ; Retrieve handle to our DPage area
  71.  
  72.                     lda [DPHandle]      ; Dereference the handle to get a ptr
  73.                     sta DPPointer       ; to our direct page area and save it.
  74.  
  75.                     PushWord DPPointer  ; QuickDraw uses 3 pages of Dpage
  76.                     PushWord #ScreenMode ; Used to set all master SCB's
  77.                     PushWord #0         ; Zero means use default buf size
  78.                     PushWord MyID       ; Application ID for allocating data
  79.                     _QDStartup          ; Start QuickDraw, turn on SHR Screen
  80.                     bcc IT0015
  81.                     brl FatalError      ; If it can't be started then bomb
  82.  
  83. IT0015              ANOP
  84.                     lda DPPointer       ; Create address for Event Mgr DPage by
  85.                     clc                 ; loading in the pointer to the start
  86.                     adc #EMDPage        ; of DPage and adding Evt Mgr offset.
  87.                     pha                 ; Now push it on the stack.
  88.                     PushWord #20        ; Size of event queue.
  89.                     PushWord #0         ; MouseClamp values.
  90.                     PushWord #ScreenWidth ; These will clamp mouse to screen
  91.                     PushWord #0         ; area only.
  92.                     PushWord #200
  93.                     PushWord MyID
  94.                     _EMStartup          ; Start the event manager
  95.                     bcc IT0020
  96.                     brl FatalError      ; Event manager is also a must
  97. IT0020              ANOP
  98.                     PushWord MyID
  99.                     _WindStartup
  100.                     bcc IT0025
  101.                     brl FatalError
  102. IT0025              ANOP
  103.                     PushWord MyID
  104.                     lda DPPointer
  105.                     clc
  106.                     adc #CtlDPage
  107.                     pha
  108.                     _CtlStartup
  109.                     bcc IT0030
  110.                     brl FatalError
  111. IT0030              ANOP
  112.  
  113.                     PushWord MyID
  114.                     lda DPPointer
  115.                     clc
  116.                     adc #MenuDPage
  117.                     pha
  118.                     _MenuStartUp
  119.                     bcc IT0035
  120.                     brl FatalError
  121. IT0035              ANOP
  122.                     PushWord MyID
  123.                     lda DPPointer
  124.                     clc
  125.                     adc #LEDPage
  126.                     pha
  127.                     _LEStartUp
  128.                     bcc IT0040
  129.                     brl FatalError
  130. IT0040              ANOP
  131.                     PushWord MyID
  132.                     _DialogStartup
  133.                     bcc IT0045
  134.                     brl FatalError
  135. IT0045              ANOP
  136.                     _ScrapStartup       ; No errors possible for this call
  137.  
  138.                     _DeskStartup        ; No error possible for this call
  139.  
  140. ; insert application specific tools here
  141.  
  142.                     PushLong #0
  143.                     _RefreshDeskTop
  144.  
  145. ;
  146. ; Create the menus I need
  147. ;
  148.  
  149.                     ldx #MenuPtrLen-4   ; Get a pointer to the last menu        
  150. loop                phx                 ; Save menu table index on the stack
  151.                     pha                 ; Push on space for the menu handle
  152.                     pha                 ;   returned by NewMenu
  153.                     lda MenuPtr+2,x     ; Push on the pointer to the template
  154.                     pha                 ;   to be used by NewMenu when
  155.                     lda MenuPtr,x       ;   creating the menu
  156.                     pha
  157.                     _NewMenu            ; Create a new menu
  158.                     PushWord #0         ; Tell InsertMenu where to put it
  159.                     _InsertMenu         ; Insert it.
  160.                     plx                 ; Get our index back off the stack
  161.                     dex                 ; Point to the next template pointer
  162.                     dex
  163.                     dex
  164.                     dex
  165.                     bpl loop            ; Go back up if not done yet.
  166.  
  167.                     PushWord #1         ; Add NDA's
  168.                     _FixAppleMenu
  169.  
  170.                     pha                 ; Now call CalcMenuSize for all menus
  171.                     _FixMenuBar
  172.                     PullWord MenuHeight
  173.  
  174.                     _DrawMenuBar        ; Finally, draw it.
  175.  
  176.                     RTS
  177.  
  178. ToolTable           dc i2'6'            ; Data Block for LoadTools call
  179.                     dc i2'14,$0100'     ; Window Manager
  180.                     dc i2'15,$0100'     ; Menu Manager
  181.                     dc i2'16,$0100'     ; Control Manager
  182.                     dc i2'20,$0100'     ; LineEdit tool set
  183.                     dc i2'21,$0100'     ; Dialog Manager
  184.                     dc i2'22,$0100'     ; Scrap manager
  185.  
  186.                     end
  187.  
  188.                     EJECT
  189. *******************************************************************************
  190. *
  191. FatalError          start
  192. *
  193. * Description:      Routine that is called whenever a tool sends back an error
  194. *                   that can not be recovered from. This routine prints the
  195. *                   error on the screen, waits for a keypress then quits back
  196. *                   to whoever started this application up!
  197. *
  198. *
  199. * Inputs:           A = Error number
  200. *
  201. * Outputs:          NONE (program exits)
  202. *
  203. * External Refs:
  204. *                   Import CloseTools
  205. *
  206. * Entry Points:     NONE
  207. *
  208. *******************************************************************************
  209.                     using Globals
  210.  
  211.                     pha                 ; Push the error code
  212.                     PushLong #ErrNumStr ; Address of storage area
  213.                     PushWord #4         ; Length of string
  214.                     _Int2Hex
  215.  
  216.                     _GrafOff            ; If QD Started, shut off graphics
  217.  
  218.                     PushLong #ErrStr    ; Write error message to the screen
  219.                     _WriteCString
  220.  
  221.                     pha                 ; Space for result
  222.                     PushWord #0         ; No echo
  223.                     _ReadChar           ; Wait for a key to be pressed
  224.                     pla                 ; Discard the key
  225.  
  226.                     jsr CloseTools      ; Shut down all the tools in case
  227. ;                                         any got started up
  228.  
  229.                     _Quit QuitParms     ; Quit back to where we came from.
  230.  
  231.                     brk $FF             ; If the quit fails then just break
  232.                     
  233. ErrStr              dc c'A fatal error has occured $'
  234. ErrNumStr           dc c'xxxx   press any key to exit'
  235.                     dc i1'0'
  236.  
  237.                     end
  238.  
  239.                     EJECT
  240. *******************************************************************************
  241. *
  242. CloseTools          start
  243. *
  244. * Description:      Shut down the tools I started.
  245. *
  246. *
  247. * Inputs:           NONE
  248. *
  249. * Outputs:          NONE
  250. *
  251. * External Refs:    NONE
  252. *
  253. * Entry Points:     NONE
  254. *
  255. *******************************************************************************
  256.                     using Globals
  257.  
  258.                     _DeskShutDown
  259.                     _ScrapShutDown
  260.                     _DialogShutDown
  261.                     _LEShutDown
  262.                     _MenuShutDown
  263.                     _CtlShutDown
  264.                     _WindShutDown
  265.                     _EMShutDown
  266.                     _QDShutDown
  267.                     _MTShutDown
  268.  
  269.                     PushLong DPHandle   ; Dispose of all that DP memory
  270.                     _DisposeHandle
  271.  
  272.                     PushWord MyID
  273.                     _MMShutDown
  274.                     _TLShutDown
  275.  
  276.                     rts
  277.                     end
  278.  
  279.                     EJECT
  280. *******************************************************************************
  281. *
  282. doAbout             start
  283. *
  284. * Description:      Bring up an Alert Dialog box with our name in it.
  285. *
  286. * Inputs:           NONE
  287. *
  288. * Outputs:          NONE
  289. *
  290. * External Refs:    NONE
  291. *
  292. * Entry Points:     NONE
  293. *
  294. *******************************************************************************
  295.                     using Globals
  296.  
  297.                     pha                 ; space for result
  298.                     PushLong #AboutBox  ; pointer to alert template
  299.                     PushLong #0         ; pointer to a filter proc (0=none)
  300.                     _NoteAlert
  301.                     pla                 ; get the item hit and dispose
  302.  
  303.                     rts
  304.  
  305. ; About Box alert template
  306.  
  307. AboutBox            dc i2'30,30,100,590'                    ; for 320 use 30,30,100,290
  308.                     dc i2'1'            ; this is alert # 1
  309.                     dc i1'$80'          ; draw for this stage
  310.                     dc i1'$81'          ; draw for this stage
  311.                     dc i1'$82'          ; draw for this stage
  312.                     dc i1'$83'          ; draw for this stage
  313.                     dc i4'OKButton'     ; ok button for the alert
  314.                     dc i4'AboutTitle'   ; title of the program
  315.                     dc i4'AboutAut'     ; author
  316.                     dc i4'AboutVers'    ; version number string
  317.                     dc i4'0'            ; nil to end the list
  318.  
  319. OKBTitle            dc i1'2'
  320.                     dc c'OK'
  321. OKButton            dc i2'1'
  322.                     dc i2'50,500,65,550'
  323.                     dc i2'buttonItem'
  324.                     dc i4'OKBTitle'
  325.                     dc i2'0'
  326.                     dc i2'0'            ; item flag
  327.                     dc i4'0'            ; no color table
  328.  
  329. AboutTitle          dc i2'2'
  330.                     dc i2'10,100,20,550'
  331.                     dc i2'statText+itemDisable'
  332.                     dc i4'TitleString'
  333.                     dc i2'0'
  334.                     dc i2'0'            ; item flag
  335.                     dc i4'0'            ; no color table
  336.  
  337. AboutAut            dc i2'3'
  338.                     dc i2'25,100,35,550'
  339.                     dc i2'statText+itemDisable'
  340.                     dc i4'AutString'
  341.                     dc i2'0'
  342.                     dc i2'0'            ; item flag
  343.                     dc i4'0'            ; no color table
  344.  
  345. AboutVers           dc i2'4'
  346.                     dc i2'40,100,50,550'
  347.                     dc i2'statText+itemDisable'
  348.                     dc i4'VersString'
  349.                     dc i2'0'
  350.                     dc i2'0'            ; item flag
  351.                     dc i4'0'            ; no color table
  352.  
  353.                     end
  354.  
  355.                     EJECT
  356. *******************************************************************************
  357. *
  358. doQuit              start
  359. *
  360. * Description:      Quit routine. Set the QuitFlag to TRUE for the EventLoop.
  361. *
  362. *
  363. * Inputs:           NONE
  364. *
  365. * Outputs:          QuitFlag set to $FFFF
  366. *
  367. * External Refs:    NONE
  368. *
  369. * Entry Points:     NONE
  370. *
  371. *******************************************************************************
  372.                     using Globals
  373.  
  374.                     lda #$FFFF
  375.                     sta QuitFlag
  376.                     rts
  377.                     end
  378.